package com.repair.system.repository;

import com.repair.system.entity.CaseLibrary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CaseLibraryRepository extends JpaRepository<CaseLibrary, Long> {
    List<CaseLibrary> findByDeviceNameContainingIgnoreCase(String deviceName);
    
    List<CaseLibrary> findByFaultPhenomenonContainingIgnoreCase(String phenomenon);
    
    @Query("SELECT c FROM CaseLibrary c WHERE " +
           "LOWER(c.deviceName) LIKE LOWER(CONCAT('%', :keyword, '%')) OR " +
           "LOWER(c.faultPhenomenon) LIKE LOWER(CONCAT('%', :keyword, '%')) OR " +
           "LOWER(c.solution) LIKE LOWER(CONCAT('%', :keyword, '%'))")
    List<CaseLibrary> searchByKeyword(@Param("keyword") String keyword);
    
    List<CaseLibrary> findByDifficultyLevel(String difficultyLevel);
}
